package com.imageflowpro.image_flow_pro.config;


import com.imageflowpro.image_flow_pro.properties.MinioProperties;
import com.imageflowpro.image_flow_pro.utils.MinioUtil;
import io.minio.MinioClient;
import jakarta.annotation.PostConstruct;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MinioConfig {

    private final MinioProperties minioProperties;


    public MinioConfig(MinioProperties minioProperties) {
        this.minioProperties = minioProperties;
    }
    //初始化minio工具类
    @Bean
    public MinioUtil minioUtil(){
        return MinioUtil.builder()
            .minioClient(
                MinioClient.builder()
                .endpoint(minioProperties.getUrl())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build()
            )
            .build();
    }
    @PostConstruct
    public void initDefaultBucket() throws Exception {
        MinioUtil minioUtil = minioUtil(); // 获取当前构造的 MinioUtil 实例
        minioUtil.bucketIsExists(minioProperties.getBucketName());
    }
}
